<template>
  <div>
    <div class="top">
      <van-sticky :offset-top="10">
        <van-button
          icon="arrow-left"
          round
          type="primary"
          color="#3EAD3E"
          size="small"
          class="button"
          @click="goBack"
        />
      </van-sticky>
      <h2>我的收藏</h2>
    </div>

    <ul>
      <router-link
        tag="li"
        :to="'/articles/' + item.id"
        v-for="item in collectionArr"
        :key="item.id"
      >
        <div class="agopages-img">
          <img :src="item.img" />
        </div>

        <div class="agopages-text">
          <p>{{ item.title }}</p>
          <span>{{ item.body }}</span>
        </div>
      </router-link>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      collectionArr: [],
    };
  },

  methods: {
    getCollectionArr() {
      let articleList = localStorage.articleList
        ? JSON.parse(localStorage.articleList)
        : [];

      this.collectionArr = articleList;
      //   console.log(this.collectionArr[0].id);
    },

    goBack() {
      this.$router.go(-1);
    },
  },
  created() {
    this.getCollectionArr();
  },
};
</script>

<style lang="scss" scoped>
.top {
  height: 50px;
  border-bottom: 1px solid #ccc;
  display: flex;
  position: relative;

  h2 {
    color: rgba(62, 173, 62, 0.731);
    font-size: 18px;
    font-weight: 600;
    line-height: 50px;
    position: absolute;
    left: 42%;
  }

  button {
    margin-left: 10px;
  }
}

li {
  display: flex;
  justify-content: space-between;
  width: 93%;
  height: 100px;
  margin: 10px auto;
  border-bottom: 1px solid #ccc;
}

.agopages-img {
  width: 36%;
  img {
    width: 100%;
    height: 80px;
    border-radius: 15px;
  }
}

.agopages-text {
  width: 54%;

  p {
    overflow: hidden; /*内容超出后隐藏*/
    text-overflow: ellipsis; /* 超出内容显示为省略号 */
    white-space: nowrap; /* 文本不进行换行 */
    padding-top: 5px;
  }

  span {
    color: #ccc;
    font-size: 13px;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    padding-top: 8px;
  }
}
</style>